package demo.database.H2.D04_导出导入;

import java.sql.Connection;

import javax.sql.DataSource;

import com.titan.common.v8.interfaces.IEmpty;
import com.titan.core.utils.db.DBUtils;
import com.titan.core.utils.db.DataSourceUtils;
import com.titan.core.utils.debug.Timer;
import com.titan.core.utils.io.ConsoleUtils;

public class D04_导出CSV {
    private static void run() throws Exception {
        String url = "jdbc:h2:file:E:/HDJT/S1502/S1502"; 
        String username = "root";
        String password = "S1502@hdjt";
        
        DataSource dataSource = DataSourceUtils.registerH2dbDataSource(IEmpty.EMPTY_ID, url, username, password, 5, 5);
        Connection conn = null;
        try {
            conn = dataSource.getConnection();
//            DBUtils.execute(conn, "CALL CSVWRITE('e:/ddm2_theme.csv', 'select * from ddm2_theme', 'charset=GBK fieldSeparator=,')");
//            DBUtils.execute(conn, "CALL CSVWRITE('e:/ddm2_theme_config.csv', 'select * from ddm2_theme_config', 'charset=GBK fieldSeparator=,')");

//            DBUtils.execute(conn, "delete from ddm2_theme_config");
//            DBUtils.execute(conn, "insert into ddm2_theme_config(select * from csvread('e:/ddm2_theme_config.csv','ID|SYSTEM_ID|THEME_LINEID|THEME_ID|PROPERTY_NAME|PROPERTY_VALUE|CREATE_NAME|CREATE_DT|UPDATE_NAME|UPDATE_DT|DELETE_FLAG|DELETE_NAME|DELETE_DT','charset=GBK fieldSeparator=,'))");
//            DBUtils.execute(conn, "insert into ddm2_theme_config(select * from csvread('e:/ddm2_theme_config.csv','ID,SYSTEM_ID,THEME_LINEID,THEME_ID,PROPERTY_NAME,PROPERTY_VALUE,CREATE_NAME,CREATE_DT,UPDATE_NAME,UPDATE_DT,DELETE_FLAG,DELETE_NAME,DELETE_DT','charset=GBK fieldSeparator=,'))");
            
            
        } finally {
            DBUtils.close(conn);
            DataSourceUtils.close(dataSource);
        }
        
    }


    public static void main(String[] args) {
        Timer timer = Timer.$();
        try {
            run();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            timer.print();
        }
    }
}
